package com.example.utils.util.SM2;

import java.math.BigInteger;
import java.util.Base64;

/**
 * @ClassName SM2UtilTest
 * @Description: TODO
 * @Author xiaojiang
 * @Version 1.0
 **/
public class SM2UtilTest {
    /** 元消息串 */
    private static String M = "";

//    public static void main(String[] args) {
//        long LoginTime = System.currentTimeMillis();
//        System.out.println(LoginTime);
//        SM2Util sm2 = new SM2Util();
//
//        /*--------           获取公匙私匙对                 -----------------*/
////        SM2KeyPair keyPair = sm2.generateKeyPair();         // 获取 key
////        System.out.println("公匙=" + keyPair.getPublicKey().toString());
////        System.out.println("私匙=" + keyPair.getPrivateKey().toString());
//        /*-----------------------end--------------------------------------*/
//
//        /*--------           自定义公匙私匙对                 -----------------*/
//        BigInteger PrivateKey = new BigInteger("81476652383335556452076726798808124701794944913884031671676154437449687336854");
////        ECPoint PublicKey = sm2.getG(PrivateKey).normalize();
////        /*-----------------------end--------------------------------------*/
////
////        byte[] data = sm2.encrypt(M, PublicKey);
////        //Base64 Encoded
////        String encoded = Base64.getEncoder().encodeToString(data);
////        System.out.println(encoded);
////        //Base64 Decoded
////        byte[] decoded = Base64.getDecoder().decode(encoded);
////        System.out.println(Arrays.toString(decoded));
////
////        System.out.println("data is:"+ Arrays.toString(data));
//
//        String password = "BB3hCyyLCy9ffRgPuEMtsDohHcO8DdiRUxy3LX4x87//iJSxT88aMZP3RdDosIdxKbLPnG88kQOyL3lWf/BW1shlZHtrIxyqMJNmXUbtn9rQ267RNOkpQMkBAta+lWpFAxWO0TY=";
//
//        String decrypt = sm2.decrypt(Base64.getDecoder().decode(password), PrivateKey);
////        String decrypt = sm2.decrypt(Base64.getDecoder().decode(password), PrivateKey);//71017045908707391874054405929626258767106914144911649587813342322113806533034
//        System.out.println("解密=" + decrypt);
//        long beginTime = System.currentTimeMillis();   // 毫秒
//        System.out.println(beginTime);
//        System.out.println("总用时=" + (LoginTime-beginTime));
//    }

    public static void main(String[] args) {
        long LoginTime = System.currentTimeMillis();
        System.out.println(LoginTime);
        SM2Util sm2 = new SM2Util();

        /*--------           获取公匙私匙对                 -----------------*/
//        SM2KeyPair keyPair = sm2.generateKeyPair();         // 获取 key
//        ECPoint PublicKey = keyPair.getPublicKey();
//        BigInteger PrivateKey = keyPair.getPrivateKey();
//        System.out.println("公匙= " + keyPair.getPublicKey().toString());
//        System.out.println("私匙= " + keyPair.getPrivateKey().toString());
        /*-----------------------end--------------------------------------*/

        /*--------           自定义公匙私匙对                 -----------------*/
        BigInteger PrivateKey = new BigInteger("45666848317442077248920409648826016378377386665000297387948515223319986101367");
//        ECPoint PublicKey = sm2.getG(PrivateKey).normalize();
//        /*-----------------------end--------------------------------------*/
//
//        byte[] data = sm2.encrypt("root", PublicKey);
        //Base64 Encoded
//        String encoded = Base64.getEncoder().encodeToString(data);
//        System.out.println("加密后= " + encoded);
        //Base64 Decoded
//        byte[] decoded = Base64.getDecoder().decode(encoded);
//        System.out.println(Arrays.toString(decoded));

//        System.out.println("data is:"+ Arrays.toString(data));

        String password = "BDXMekT8MyiFwDjwPiOSqx386yzhsxOiEujnPzcgIXxniJ/SZ83x20dEsA26bd2H0QeVTzqEpBI2Mo26YRKyaF5eUggNWM4InejJsgNF+ayECiLM1uRIxsk=";

        String decrypt = sm2.decrypt(Base64.getDecoder().decode(password), PrivateKey);
//        String decrypt = sm2.decrypt(Base64.getDecoder().decode(password), PrivateKey);//71017045908707391874054405929626258767106914144911649587813342322113806533034
        System.out.println("解密=" + decrypt);
        long beginTime = System.currentTimeMillis();   // 毫秒
        System.out.println(beginTime);
        System.out.println("总用时=" + (LoginTime-beginTime));
    }
}
